package dhm.com.dhmshop.updata.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dhm.com.dhmshop.R;
import dhm.com.dhmshop.base.BaseActiity;
import dhm.com.dhmshop.base.Presenter.PressenterImpl;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.base.netWork.LoginContract;
import dhm.com.dhmshop.entity.GetShopDetailBean;
import dhm.com.dhmshop.utils.SpUtils;

public class ShopintroduceActivity extends BaseActiity implements LoginContract.IView {

    @BindView(R.id.shop_image)
    SimpleDraweeView shopImage;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.checkshop)
    TextView checkshop;
    @BindView(R.id.timecount)
    TextView timecount;
    @BindView(R.id.servicecount)
    TextView servicecount;
    @BindView(R.id.goodscount)
    TextView goodecount;
    @BindView(R.id.shopAddress)
    TextView shopAddress;
    @BindView(R.id.shopTel)
    TextView shopTel;
    @BindView(R.id.serviceTime)
    TextView serviceTime;
    @BindView(R.id.shop_invoice)
    TextView shopInvoice;
    @BindView(R.id.accreds)
    TextView accreds;
    private String shop_id;
    private PressenterImpl pressenter;
    private GetShopDetailBean getShopDetailBean;

    @Override
    protected int getLayout() {
        return R.layout.activity_shopintroduce;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        shop_id = getIntent().getStringExtra("shop_id");
        pressenter = new PressenterImpl();
        pressenter.attachView(this);

        String uid = SpUtils.getString(this, "uid");
        Map<String, String> map = new HashMap<>();
        map.put("token", Constant.TOKEN);
        map.put("uid",uid);
        map.put("shop_id", shop_id);
        pressenter.sendMessage(this, Constant.GetShopInfo, map, GetShopDetailBean.class);

    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.back, R.id.shopservice, R.id.checkshop})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.shopservice:
                break;
            case R.id.checkshop:
                if (getShopDetailBean.getData().getIs_collect()==1){
//                    关注了

                }else {
//                    未关注

                }
                break;
                default:
        }
    }

    @Override
    public void requesta(Object data) {
        if (data instanceof GetShopDetailBean){
            getShopDetailBean = (GetShopDetailBean) data;

            shopImage.setImageURI(Constant.PATH+"/"+ getShopDetailBean.getData().getShopImg());
            name.setText(getShopDetailBean.getData().getShopName());
            shopAddress.setText(getShopDetailBean.getData().getShopAddress());
            servicecount.setText(getShopDetailBean.getData().getShop_scores().getServiceScore());
            timecount.setText(getShopDetailBean.getData().getShop_scores().getTimeScore());
            goodecount.setText(getShopDetailBean.getData().getShop_scores().getGoodsScore());
            shopTel.setText(getShopDetailBean.getData().getShopTel());
            serviceTime.setText(getShopDetailBean.getData().getServiceStartTime()+"-"+ getShopDetailBean.getData().getServiceEndTime());
            shopInvoice.setText(getShopDetailBean.getData().getShop_invoice());
            String a="";
            for (int i = 0; i< getShopDetailBean.getData().getAccreds().size(); i++){
                a=a+ getShopDetailBean.getData().getAccreds().get(i).getGoods_name()+"、";
            }
            if (a.length()>0){
                a.substring(0,a.length()-1);
            }
            accreds.setText(a);
            if (getShopDetailBean.getData().getIs_collect()==1){
//                    关注了
                checkshop.setText("已关注");
            }else {
//                    未关注
                checkshop.setText("关注店铺");
            }
        }
    }

    @Override
    public void fail(String error) {

    }
}
